|
|
Hi philippe, I'm not certain to really understand what you are looking for.
I don't understand why union is better than difference. In this case, as
there are many
coincident surfaces, I would use a merge.
Anyway I wrote this, it seems to work.
Chaps
// Persistence of Vision Ray Tracer Scene Description File
// File: ?.pov
// Vers: 3.5
// Desc: Basic Scene Example
// Date: mm/dd/yy
// Auth: ?
//
#version 3.5;
#include "colors.inc"
global_settings {
assumed_gamma 1.0
}
// ----------------------------------------
camera {
location <0.0, 15, -15>
direction 1.5*z
right x*image_width/image_height
look_at <0.0, 0.0, 0.0>
}
light_source {
<0, 0, 0> // light's position (translated below)
color rgb <1, 1, 1> // light's color
translate <-30, 30, -30>
}
// ----------------------------------------
#macro DiffToUnion (C1,C2,C3,C4)
//C1,C2 are the corner of the "+" box
//C3,C4 are the corner of the"-" box
#local UP1 = max(C1.y,C2.y);
#local BOT1 = min(C1.y,C2.y);
#local LEFT1 = min(C1.x,C2.x);
#local RIGHT1 = max(C1.x,C2.x);
#local FRONT1 = min(C1.z,C2.z);
#local REAR1 = max(C1.z,C2.z);
#local UP2 = max(C3.y,C4.y);
#local BOT2 = min(C3.y,C4.y);
#local LEFT2 = min(C3.x,C4.x);
#local RIGHT2 = max(C3.x,C4.x);
#local FRONT2 = min(C3.z,C4.z);
#local REAR2 = max(C3.z,C4.z);
#local NewObj = union {
// is there a Top
#if (UP1 > UP2)
box { <LEFT1,UP1,FRONT1>,<RIGHT1,UP2,REAR1>}
#end
// is there a bottom
#if (BOT1 < BOT2)
box { <LEFT1,BOT2,FRONT1>,<RIGHT1,BOT1,REAR1>}
#end
// is there a right
#if (RIGHT1 > RIGHT2)
box { <RIGHT2,UP1,FRONT1>,<RIGHT1,BOT1,REAR1>}
#end
// is there a bottom
#if (LEFT1 < LEFT2)
box { <LEFT1,UP1,FRONT1>,<LEFT2,BOT1,REAR1>}
#end
// is there a rear
#if (REAR1 > REAR2)
box { <LEFT1,UP1,REAR2>,<RIGHT1,BOT1,REAR1>}
#end
// is there a front
#if (FRONT1 < FRONT2)
box { <LEFT1,UP1,FRONT1>,<RIGHT1,BOT1,FRONT2>}
#end
}
object { NewObj}
#end
#declare A1 = <-2,2,2>;
#declare A2 = <2,-2,-2>;
#declare A3 = <-1,-1,-3>;
#declare A4 = <1,1,3>;
difference {
box { A1,A2 }
box { A3,A4 }
pigment { color Blue }
translate -4*x
}
object {
DiffToUnion(A1,A2,A3,A4)
pigment { color Red }
translate 4*x
}
"Philippe Debar" <phd### [at] yahoofr> wrote in message
news:3BC### [at] yahoofr...
> For once, I don't want to re-invent the wheel, so :
>
> I'd like to write a macro to replace a difference of boxes (plain
> vanilla box, no transform, not even translate) with a spacially
> equivalent union of boxes.
>
> (1) does it already exist ?
>
> if not
>
> (2) there are many possible solutions, how to find an optimal one ? And
> what would be optimum speed-wise ? (I guess less boxes, size
> irrevelant). I suppose this problem must have been studied already...
> Can anybody give me a link ?
>
>
> TIA
>
> Philippe
>
Post a reply to this message
|
|